 package com.gmrz.uaf.protocol.v1.json;
 
 import com.google.gson.InstanceCreator;
 import com.google.gson.JsonArray;
 import com.google.gson.JsonDeserializationContext;
 import com.google.gson.JsonDeserializer;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonParseException;
 import com.google.gson.JsonSerializationContext;
 import com.google.gson.JsonSerializer;
 import com.gmrz.uaf.protocol.v1.schema.ListAttestationCerts;
 import com.gmrz.util.Convert;
 import java.io.ByteArrayInputStream;
 import java.lang.reflect.Type;
 import java.security.cert.Certificate;
 import java.security.cert.CertificateEncodingException;
 import java.security.cert.CertificateException;
 import java.security.cert.CertificateFactory;
 import java.util.Iterator;
 
 public class ListAttestationCertsAdapter
   implements InstanceCreator<ListAttestationCerts<?>>, JsonSerializer<ListAttestationCerts<?>>, JsonDeserializer<ListAttestationCerts<?>>
 {
   public ListAttestationCerts<?> createInstance(Type type)
   {
     return new ListAttestationCerts();
   }
 
   public JsonElement serialize(ListAttestationCerts<?> src, Type typeofSrc, JsonSerializationContext context)
   {
     JsonArray a = new JsonArray();
     for (Iterator i$ = src.iterator(); i$.hasNext(); ) { Object o = i$.next();
       Certificate c = (Certificate)o;
       try {
         a.add(context.serialize(Convert.toBase64(c.getEncoded())));
       } catch (CertificateEncodingException e) {
         e.printStackTrace();
       }
     }
 
     return a;
   }
 
   public ListAttestationCerts<?> deserialize(JsonElement json, Type typeofT, JsonDeserializationContext context)
     throws JsonParseException
   {
     ListAttestationCerts retval = new ListAttestationCerts();
     JsonArray array = json.getAsJsonArray();
     for (JsonElement je : array) {
       try {
         CertificateFactory factory = CertificateFactory.getInstance("X.509");
         Certificate c = factory.generateCertificate(new ByteArrayInputStream(Convert.fromBase64(je.getAsString())));
 
         retval.add(c);
       }
       catch (CertificateException e) {
         e.printStackTrace();
       }
     }
     return retval;
   }
 }
